package com.mxprojects.admin
{
	import com.mxprojects.constructors.OptionArrow;
	import com.mxprojects.constructors.SimpleTextField;
	import com.mxprojects.language.Language;
	import com.mxprojects.language.Word;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class AdminOptions extends Sprite
	{
		private const FONT_SIZE:int = 10;
		
		private var optionText:SimpleTextField;
		private var optionArrow:OptionArrow;
		private var isOpen:Boolean = false;
		
		public function AdminOptions() {
			//add the text for the roll down
			optionText = new SimpleTextField(Language.main(Word.OPTIONS), FONT_SIZE);
			addChild(optionText);
			
			//add the arrow toggle
			optionArrow = new OptionArrow();
			optionArrow.x = optionText.x - optionArrow.width*2;
			optionArrow.y = Math.round(optionText.height/2 - optionArrow.height/2);
			addChild(optionArrow);
			
			//handle the mouse
			optionText.addEventListener(MouseEvent.CLICK, toggle, false, 0, true);
			optionArrow.addEventListener(MouseEvent.CLICK, toggle, false, 0, true);
		}
		
		private function toggle(event:MouseEvent):void {
			//open and close dem options
			if(isOpen){
				close();
			}else{
				open();
			}
			
			//set the option arrow
			optionArrow.setState(isOpen);
		}
		
		private function open():void {
			//show all the options
			isOpen = true;
		}
		
		private function close():void {
			//hide everything
			isOpen = false;
		}

	}
}